@extends('layouts.home')

@section('content')
    <div class="layui-card">
        <div class="layui-card-header">网站认领</div>
        <div class="layui-card-body">
            <form class="layui-form layui-form-pane site-add-data" action="">
                <div class="layui-form-item">
                    <label class="layui-form-label">网站域名</label>
                    <div class="layui-input-inline">
                        <input type="text" name="url" required="" lay-verify="required" placeholder="例如：www.021xw.com" class="layui-input" value="@if(isset($url)) {{ $url }} @endif">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit="" lay-filter="formSite">下一步</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
    @if(isset($token))
        <div class="layui-row layui-col-space15" style="margin-bottom: 0">
        <div class="layui-col-md5">
            <div class="layui-card">
                <div class="layui-card-header">方法一 文件验证</div>
                <div class="layui-card-body">
                    <div class="claim-text font-size-12">
                        <p>第一步：<a href="{{ url('website/claimDown') }}" target="_blank" id="dowm_file_url">下载验证文件 <i class="iconfont icon-down"></i> </a></p>
                        <p>第二步：放置在域名（<em id="url">{{ $url }}</em>）的根目录</p>
                        <p>第三步：<em id="to_url_test"><a href="http://{{ $url }}/{{ $url }}.txt" target="_blank">[测试访问]</a></em></p>
                        <button class="layui-btn layui-btn-sm check-Site" data-type="file">开始验证</button>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-col-md7">
            <div class="layui-card">
                <div class="layui-card-header">方法二 标签验证</div>
                <div class="layui-card-body">
                    <div class="claim-text font-size-12">
                        <p>第一步：复制以下代码:</p>
                        <p><em>&lt;meta name="check-domain" content="<em id="claim_code">{{ $token }}</em>" /&gt;</em></p>
                        <p>第二步：网站首页代码的 <em>&lt;head&gt;</em> 标签下第一行 点击验证</p>
                        <button class="layui-btn layui-btn-sm check-Site" data-type="html">开始验证</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
    @endif
@endsection

@section('scriptsAfterJs')
    @verbatim
    <script>
        layui.use(['layer', 'form','jquery','element','table','layedit','upload'], function(){
            var layer = layui.layer ,$ = layui.jquery ,form = layui.form;
            form.on('submit(formSite)', function(data){
                var loading = layer.msg('正在操作中...请稍后!', {icon: 16,skin:'loading',time: 1000*1000,shade: [0.7,'#000']});
                $.ajax({
                    headers: {
                        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                    },
                    type: "post",
                    url: "claim/host",
                    data: data.field,
                    success: function (msg) {
                        layer.close(loading);
                        if(msg.code == 1){
                            layer.msg(msg.data,{skin: msg.code,time:3000,shade: [0.7, '#000'],shadeClose:true},function () {
                                location.href= msg.url;
                            });
                        }else{
                            layer.msg(msg.data,{skin: msg.code,time:3000,shade: [0.7, '#000'],shadeClose:true});
                        }
                    },
                    error: function () {
                        layer.close(loading);
                    }
                });
                return false;
            });
            $('.check-Site').on('click',function(){
                var loading = layer.msg('正在操作中...请稍后!', {icon: 16,skin:'loading',time: 1000*1000,shade: [0.7,'#000']});
                var type = $(this).data('type');
                if(type == 'file'){
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        type: "post",
                        url: "claim/file",
                        success: function (msg) {
                            layer.close(loading);
                            if(msg.code == 1){
                                layer.msg(msg.data,{skin: msg.code,time:3000,shade: [0.7, '#000'],shadeClose:true},function () {
                                    location.href= msg.url;
                                });
                            }else{
                                layer.msg(msg.data,{skin: msg.code,time:3000,shade: [0.7, '#000'],shadeClose:true});
                            }
                        },
                        error: function () {
                            layer.close(loading);
                        }
                    });
                }
                if(type == 'html'){
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        type: "post",
                        url: "claim/html",
                        success: function (msg) {
                            layer.close(loading);
                            if(msg.code == 1){
                                layer.msg(msg.data,{skin: msg.code,time:3000,shade: [0.7, '#000'],shadeClose:true},function () {
                                    location.href= msg.url;
                                });
                            }else{
                                layer.msg(msg.data,{skin: msg.code,time:3000,shade: [0.7, '#000'],shadeClose:true});
                            }
                        },
                        error: function () {
                            layer.close(loading);
                        }
                    });
                }
                return false;
            });
        });
    </script>
    @endverbatim
@endsection
